package me.zhengjie.modules.system.service.mapstruct;

import me.zhengjie.base.BaseMapper;
import me.zhengjie.modules.system.domain.Requirement;
import me.zhengjie.modules.system.service.dto.RequirementDto;
import me.zhengjie.modules.system.service.mapstruct.convertor.impl.RequirementConvertor;
import org.mapstruct.InjectionStrategy;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.ReportingPolicy;

/**
 * RequirementMapper
 *
 * @author guoyuan
 * @version 1.0.0
 * @since 1.0.0
 */
@Mapper(componentModel = "spring", uses = {RequirementConvertor.class, SystemMapper.class}, unmappedTargetPolicy = ReportingPolicy.IGNORE, injectionStrategy = InjectionStrategy.CONSTRUCTOR)
public interface RequirementMapper extends BaseMapper<RequirementDto, Requirement> {

    /**
     * DTO转Entity
     *
     * @param dto /
     * @return /
     */
    @Override
    @Mappings({@Mapping(target = "requirementTheme", source = "requirementTheme", qualifiedByName = "requirementThemePenetrate"),
            @Mapping(target = "requirementDesc", source = "requirementDesc", qualifiedByName = "requirementDescPenetrate"),
            @Mapping(target = "system", expression = "java(systemMapper.toEntity(dto.getSystem()))"),
            @Mapping(target = "requirementId", expression = "java(requirementConvertor.requirementId2Integer(dto.getRequirementId()))")})
    Requirement toEntity(RequirementDto dto);

    /**
     * Entity转DTO
     *
     * @param entity /
     * @return /
     */
    @Override
    @Mappings({@Mapping(target = "requirementTheme", source = "requirementTheme", qualifiedByName = "requirementThemePenetrate"),
            @Mapping(target = "requirementDesc", source = "requirementDesc", qualifiedByName = "requirementDescPenetrate"),
            @Mapping(target = "system", expression = "java(systemMapper.toDto(entity.getSystem()))"),
            @Mapping(target = "requirementId", expression = "java(requirementConvertor.requirementId2String(entity.getRequirementId(), entity.getCreateTime()))")})
    RequirementDto toDto(Requirement entity);
}
